package common.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

import common.code.CodeMap;

/**
 * <pre>
 * 공통 예외
 * 2012.05.14 : 신규작성 (박상헌)
 * </pre>
 * @author 박상헌
 *
 */
public class BizException extends Throwable {
	private String code = "NONE";
	private String message = "NO MESSAGE";
	
	public BizException(String code) {
		super();
		this.code = code;
	}
	
	public BizException(String code, String message) {
		super(message);
		this.code = code;
	}
	
	public BizException(String code, String message, Throwable cause) {
		super(message, cause);
		this.code = code;
	}
	
	public BizException(String code, Throwable cause) {
		super(cause);
		this.code = code;
	}
	
	public String stackTrace() {
		StringWriter writer = new StringWriter();
		PrintWriter printWriter = new PrintWriter(writer);
		
		StringBuffer buffer = new StringBuffer();
		buffer.append("BizException Code : [");
		buffer.append(this.code);
		buffer.append(":");
		buffer.append(this.message);
		buffer.append("]\n");
		
		this.printStackTrace(printWriter);
		
		return writer.toString();
	} // stackTrace();
	
	public void setCode(String code) {
		CodeMap codeMap = CodeMap.getInstance();
		String message = codeMap.error(this.code);
		this.code = code;
		this.message = message;
	} // setCode()
} // class BizException
